<template>
  <div class="container container_province">
    <!-- 搜索 -->
    <div class='m_search'>
      <img src='https://img.ameimeika.com/active/ba3955e3460bee281fcdcca66e719913.png' />
      <input v-model="keyword" @confirm='searchkeyword' class='s_input' placeholder='请输入素材名称'
        placeholder-class='s_place' />
      <img src='https://img.ameimeika.com/server/82e8fe6e91918806b75255d116c3810c.png' class='clearImg'
        @click='clear' />
      <div @click='goback' class='cancel'>取消</div>
    </div>
    <scroll-view :scroll-y="true" :style="{'height': clientHeight+'px'}" @scrolltolower="infinite_scroll">
      <!-- 素材列表 -->
      <div class='section_list' v-if="listarr.length>0">
        <div class='col'>  
          <!-- 素材列表item -->
          <div @click='todetails(item.class,item.id)' :key="index" v-for="(item,index) in listarr" class='sec_item'>
            <div class='imgbox'>
              <image mode='aspectFit' v-if="item.mini_url" :src='imgUrl+item.mini_url'></image>
              <div v-if="item.class == 2" class='mask'>
                <img src='https://img.ameimeika.com/active/1efc6d65c2d9cb1b0ffecd66a8a415f8.png' />
              </div>
            </div>
            <div class='title'>{{item.title}}</div>

          </div>
          <!-- 素材列表item end-->
        </div>
      </div>

      <!-- 素材列表占位符 -->
      <div v-else class='orderholder'>
        <img src='https://img.ameimeika.com/active/d6eb8722443cb0715bd805b8798587d7.png' />
        <div>暂未搜到相关素材～换个词儿试试吧</div>
      </div>
    </scroll-view>
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
export default {
  data() {
    return {
      clientHeight: 0,
      imgUrl: common.image_response,
      isshow: false, //占位符
      listarr: [], // 素材列表
      page: 1,
      pageSize: 6,
      type: "", // 素材类别id
      province_id: 13, // 省份id
      mclass: 0, //素材类型  0 全部  1 图片  2视频
      keyword: "" //搜索关键词
    };
  },
  methods: {
    infinite_scroll() {
      this.page++;
      this.getData();
    },
    getData() {
      var data = {
        page: this.page,
        pageSize: this.pageSize,
        keyword: this.keyword,
        province_id: this.province_id
      };
      common.mmk_Loading(0);
      common.fly_post("/api/act/material/material_s_list", data, msg => {
        common.mmk_Loading(1);
        let res = msg.data;
        if (res.status_code == 0) {
          this.listarr = this.listarr.concat(res.data);
        } else {
          common.mmk_Loading(2, res.message);
        }
      });
    },
    goback: function() {
      wx.navigateBack({
        delta: 1
      });
    },
    //清除输入框内容
    clear: function() {
      this.keyword = "";
    },
    //跳转详情
    todetails(classs, id) {
      var that = this;
      var mid = id;
      var classs = classs;
      wx.getStorage({
        key: "user_token",
        success: response => {
          //   已登录
          wx.navigateTo({
            url: `/pages/material_center/material_del/main?mid=${mid}&class=${classs}&page=${
              that.page
            }`
          });
        },
        fail: () => {
          //   未登录
          wx.navigateTo({
            url: "/pages/package_main/login/main"
          });
        },
        complete: () => {}
      });
    },
    //再次输入搜索
    searchkeyword() {
      this.page = 1;
      this.listarr = [];
      this.getData();
    }
  },
  onLoad(options) {
    let that = this;
    wx.setNavigationBarTitle({
      title: "搜索"
    });
    wx.getSystemInfo({
      success: function(res) {
        // 获取可使用窗口宽度
        that.clientHeight = res.windowHeight;
      }
    });
    that.province_id = options.province_id;
    that.keyword = options.keyword;
    that.page = 1;
    that.listarr = [];
    that.getData();
  },
  onShow() {},
  watch: {}
};
</script>

<style lang="less" scoped>
/* material_search.wxss */
.container_msearch {
  min-height: 100%;
  background: #fff;
}
/* 搜索 */
.s_place {
  font-size: 13px;
  color: #999;
  line-height: 32px;
}
.m_search {
  height: 43px;
  width: 92%;
  background: #fff;
  padding: 0 4%;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.zhanwei{
  width: 100%;
  height: 200px;
}
.m_search image {
  width: 25px;
  height: 25px;
  position: absolute;
  top: 12px;
  left: 25px;
}
.m_search .s_input {
  width: 75%;
  height: 32px;
  line-height: 32px;
  background: #f5f5f5;
  border-radius: 16px;
  margin-top: 7px;
  padding-left: 40px;
  color: #333;
  font-size: 14px;
}
.m_search .cancel {
  font-size: 14px;
  width: 12%;
  text-align: center;
  line-height: 43px;
}
/* 素材列表 */
.section_list {
  display: flex;
  margin-top: 5px;
  padding-top: 50px;
}
.section_list .col {
  width: 100%;
  columns: 2;
  flex-wrap: nowrap;
  padding: 0 4%;
}
.section_list .col_r {
  width: 45%;
  display: flex;
  flex-direction: column;
  padding: 0 4% 0 1%;
}
.section_list .sec_item {
  width: 100%;
  font-size: 0;
  margin-bottom: 15px;
  break-inside: avoid;
}
.section_list .sec_item .imgbox {
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 5px;
  text-align: center;
  position: relative;
}
.section_list .sec_item .minimgbox {
  position: relative;
}
.section_list .sec_item .imgbox .mask image {
  width: 40px;
  height: 40px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-20px) translateY(-20px);
}
.section_list .sec_item .minimgbox {
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 5px;
  text-align: center;
  position: relative;
}
.section_list .sec_item .minimgbox image {
  width: 100%;
  min-height: 10px;
}
.section_list .sec_item .minimgbox .mask image {
  width: 40px;
  height: 40px;
  opacity: 0.6;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-20px) translateY(-20px);
}
.section_list .sec_item .minimgbox {
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 5px;
}
.section_list .sec_item .imgbox image {
  width: 100%;
  max-height: 228px;
}
.section_list .sec_item .title {
  font-size: 14px;
  margin: 3% 0;
}
.section_list .sec_item .like_msg {
  display: flex;
  font-size: 10px;
  color: #999;
}
.section_list .sec_item .like_msg .favorite {
  height: 20px;
  line-height: 20px;
  width: 30%;
}
.section_list .sec_item .like_msg .comment {
  height: 20px;
  line-height: 20px;
  width: 30%;
}
.section_list .sec_item .like_msg .favorite image {
  width: 16px;
  height: 16px;
  vertical-align: top;
  margin-top: 2px;
}
.section_list .sec_item .like_msg .comment image {
  width: 15px;
  height: 15px;
  vertical-align: top;
  margin-top: 2px;
}

/* 素材占位符 */
.orderholder {
  width: 128px;
  height: 114px;
  margin-top: 40%;
  margin-left: 50%;
  transform: translateX(-64px);
}
.orderholder image {
  width: 100%;
  height: 100%;
}
.orderholder view {
  font-size: 14px;
  color: #666;
  text-align: center;
}

.m_search .clearImg {
  width: 18px;
  height: 18px;
  position: absolute;
  top: 15px;
  left: 76%;
  z-index: 10;
}
</style>

